﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HYI.SDBSERVER
{
    class LogFile
    {
        /*
         保存日志文件
         */

       public void doWriteLog(int iType,string sMsg)
       {
           string path = System.Environment.CurrentDirectory+"\\Log";
           if (! Directory.Exists(path))//判断是否存在
           {
               Directory.CreateDirectory(path);//创建新路径
           }

           string sFlag="";

           string sDate = sFlag + DateTime.Now.ToString("yyyyMMdd") + ".TXT";
           string sLogFile = path + "\\"+sDate;
           Console.WriteLine("当前文件:" + sLogFile);

           if (File.Exists(sLogFile))
           {   //文件存在就追加
               StreamWriter sw = File.AppendText(sLogFile);
               sw.WriteLine(DateTime.Now.ToString("HH:mm:ss") + ":"+sMsg);
               sw.Flush();
               sw.Close();
           }
           else
           {
              //文件不存在就创建
               StreamWriter rw = File.CreateText(sLogFile);
               rw.WriteLine(DateTime.Now.ToString("HH:mm:ss") + ":" + sMsg);
               rw.Flush();
               rw.Close();
           }
         }
    }
}
